package com.guslegend.Class01_ioc.test;

import com.guslegend.Class01_ioc.HappyPlay;
import com.guslegend.Class01_ioc.HappyTime;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author: guslegend
 * @description: 作用域测试
 * @create: 2025-04-27 11:34
 **/
public class Scope {

    @Test
    public void testScope(){
        ApplicationContext iocContainer=
                new ClassPathXmlApplicationContext("bean3.xml");

        HappyPlay bean=iocContainer.getBean("happyPlay5",HappyPlay.class);
        HappyPlay bean1=iocContainer.getBean("happyPlay5",HappyPlay.class);
        //多例对比 false
        System.out.println(bean == bean1);

        HappyTime bean2=iocContainer.getBean("happyPlay6",HappyTime.class);
        HappyTime bean3=iocContainer.getBean("happyPlay6",HappyTime.class);
        //单例对比 true
        System.out.println(bean2 == bean3);
    }

    @Test
    public void test(){
        ApplicationContext iocContainer=
                new ClassPathXmlApplicationContext("bean4.xml");
    }
}
